// BondController.java
package com.geek.hero.controller;

import com.geek.hero.entity.Bond;
import com.geek.hero.result.Result;
import com.geek.hero.service.IBondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 羁绊前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-14
 */
@RestController
@RequestMapping("/bond")
@CrossOrigin
public class BondController {

    @Autowired
    private IBondService bondService;

    // 获取所有羁绊
    @GetMapping
    public Result list() {
        List<Bond> list = bondService.list();
        return new Result(true, "查询成功", list);
    }

    // 根据ID获取羁绊详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Bond bond = bondService.getById(id);
        if (bond != null) {
            return new Result(true, "查询成功", bond);
        } else {
            return new Result(false, "未找到该羁绊");
        }
    }

    // 根据名称搜索羁绊
    @GetMapping("/search")
    public Result searchByName(@RequestParam String keyword) {
        List<Bond> bondList = bondService.searchByName(keyword);
        return new Result(true, "查询成功", bondList);
    }
}
